var imgbox = require('../models/imagebox.js');

exports.showImgbox = function(req,res){
	if (req.url == '/favicon.ico') {return;}
	var arr = [];
	imgbox.select(arr,function(err,results){
		if (err) {
			res.end('查询失败');
		}else if(results!=undefined){
			res.render('index',{ data : results });
		}else{
			res.end('ERROR');
		}
	});
}

exports.addImgbox = function(req,res){
	if (req.url == '/favicon.ico') {return;}
	var imgbox_name = req.body.imgbox_name;
	var imgbox_desc = req.body.imgbox_desc;
	var tmp = Date.parse(new Date()).toString();
	var create_time = parseInt(tmp.substr(0,10));
	var arr = [imgbox_name,imgbox_desc,create_time];

	imgbox.insert(arr,function(err,results){
		if (err) {
			res.end('添加失败');
		}else if(results!=undefined && results!=null){
			res.end('<script>location.href="/";</script>');
		}else{
			res.end('ERROR');
		}
	});
}